<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>新增栏目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <link rel="stylesheet" href="/plugins/layui/css/public.css" media="all" />
    <style>
        .layui-form-label {
            width: 10%;
        }
        .layui-input-block {
            margin-left: 13%;
        }
        .required-field {
            color: red;
            margin-right: 2px;
            font-size: 15px;
            text-align: center;
        }
        img {
            width: 110px;
            height: 110px;
        }
        .layui-upload-list {
            margin-left: 13%;
        }

    </style>
</head>
<body>
<div style="margin: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>app栏目新增(<label class="layui-required-tip">标红的为必填项</label>)</legend>
    </fieldset>
    <form class="layui-form" id="layui-form" action="/manage/pro/addPro" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label layui-required-tip">栏目名称：</label>
            <div class="layui-input-block">
                <input type="text" id="columnName" name="columnName" lay-verify="required" placeholder="栏目名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-required-tip">排序：</label>
            <div class="layui-input-block">
                <input type="text" id="sort" name="sort" lay-verify="number" placeholder="排序" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">跳转地址：</label>
            <div class="layui-input-block">
                <input type="text" id="url" name="url" placeholder="跳转地址" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label layui-required-tip">栏目图片：</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="test">
                    <i class="layui-icon">&#xe67c;</i>栏目图片
                </button>
            </div>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="logoImg">
                <input type="hidden"  name="columnImg" id="columnImg"/>
                <p id="logoText"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用：</label>
            <div class="layui-input-block" id="enableFlag" >
                <input type="radio" name="enableFlag" value="1" title="启用" >
                <input type="radio" name="enableFlag" value="0" title="停用" checked>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="save">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary" >重置</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="javascript:history.back();" >返回</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/js/global-config.js"></script>
<script>
    layui.use(['jquery', 'form','upload'], function() {
        var form = layui.form,$ = layui.jquery,upload = layui.upload;

        form.render();

        layer.ready(function () {
            var $layer = $('#layui-form');
            //监听提交监听提交
            form.on('submit(save)', function(data){
                if($("#columnImg").val()==""){
                    layer.msg("请上传图片", { icon: 5, shift: 6 });
                    return false;
                }
                layer.confirm('确认要提交吗？', {
                    btn : [ '确定', '取消' ]//按钮
                }, function(index) {
                    $layer.submit();
                    layer.close(index);
                });
                return false;
            });
        })

        //执行实例
        var uploadlogo = upload.render({
            url: '/manage/upload/uploadFile',
            elem: '#test', //指定原始元素，默认直接查找class="layui-upload-file"
            size: 1000,
            before: function(obj) {
                layer.load();
            },
            done: function(res){
                //上传完毕回调
                $('#logoImg').attr('src', res.data["imgUrl"]); //图片链接（base64）
                $('#columnImg').val(res.data["key"]);
                layer.closeAll('loading');
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>
</body>
</html>